package com.chinasoft.ui;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author 中软zhang
 * @create 2023-07-25 17:00
 */
public class PlayView extends JFrame implements ActionListener {
    JPanel contentPane;
    JButton replayBtn, prevBtn, firstBtn, nextBtn, lastBtn, musicBtn, exitBtn;

    public PlayView() {
      /*  setTitle("开始玩游戏了 ！");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(200, 200, 450, 300);*/
        setTitle("开始玩游戏了");
        //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(200, 20, 1200, 1060);
        setFont(new Font("微软雅黑", Font.PLAIN, 20));
        contentPane = new JPanel();
//        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setBorder(new LineBorder(Color.GREEN ));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        // 游戏区
//        JPanel game = new JPanel();
//        game.setBackground(Color.GRAY);
//        game.setBounds(0, 0, 1000, 1000);
//        game.setVisible(true);
        GamePanel game = new GamePanel();
        contentPane.add(game);

        // 画按钮区
        JPanel btnArea = new JPanel();
        btnArea.setBackground(Color.LIGHT_GRAY);
        btnArea.setBounds(1002, 0, 176, 1000);
        btnArea.setVisible(true);
        // 非常重要
        btnArea.setLayout(null);
        btnArea.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        contentPane.add(btnArea);

        // 画按钮
        replayBtn = new JButton("重  来");
        replayBtn.setFont(new Font("隶书", Font.BOLD, 20));
        btnArea.add(replayBtn);
        replayBtn.setBounds(40, 200, 100, 30);
        replayBtn.addActionListener(this);
        firstBtn = new JButton("第 1 关");
        firstBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(firstBtn);
        firstBtn.setBounds(40, 300, 100, 30);
        firstBtn.addActionListener(this);
        prevBtn = new JButton("上一关");
        prevBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(prevBtn);
        prevBtn.setBounds(40, 400, 100, 30);
        prevBtn.addActionListener(this);
        nextBtn = new JButton("下一关");
        nextBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(nextBtn);
        nextBtn.setBounds(40, 500, 100, 30);
        nextBtn.addActionListener(this);
        lastBtn = new JButton("最终关");
        lastBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(lastBtn);
        lastBtn.setBounds(40, 600, 100, 30);
        lastBtn.addActionListener(this);
        musicBtn = new JButton("音  乐");
        musicBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(musicBtn);
        musicBtn.setBounds(40, 700, 100, 30);
        musicBtn.addActionListener(this);
        exitBtn = new JButton("退  出");
        exitBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
        btnArea.add(exitBtn);
        exitBtn.setBounds(40, 800, 100, 30);
        exitBtn.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("event is run");
        System.out.println("事件源是 ：" + e.getSource());
        if (e.getSource() == exitBtn) {
            System.out.println("game is over");
            System.exit(0);
        }
    }
}
